﻿using System.Web;
using TavDom.Library.DataAccess.Concrete.EntityFramework.ContextBase;

namespace TavDom.Library.DataAccess.Helpers
{
    public class ContextHelper
    {

        public static DatabaseContext GetContext()
        {
            DatabaseContext context;

            if (HttpContext.Current.Items["ctx"] == null)
            {
                context = new DatabaseContext();
                HttpContext.Current.Items["ctx"] = context;
            }
            else
            {
                context = (DatabaseContext)HttpContext.Current.Items["ctx"];
            }
            return context;
        }


        public static void Dispose()
        {
            GetContext().Dispose();
            HttpContext.Current.Items["ctx"] = null;
        }

    }
}
